<?php
// +----------------------------------------------------------------------
// | Quotes [ 只为给用户更好的体验]**[我知道发出来有人会盗用,但请您留版权]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 青涩  <3489621943@qq.com>          盗用不留版权,你就不配拿去!
// +----------------------------------------------------------------------
// | Date: 2021年03月24日
// +----------------------------------------------------------------------

include("../includes/common.php");
$title='订单管理';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
<style>
td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:300px;}
.form-inline .form-control {
    display: inline-block;
    width: auto;
    vertical-align: middle;
}
.form-inline .form-group {
    display: inline-block;
    margin-bottom: 0;
    vertical-align: middle;
}
</style>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>订单管理</title>
<link href="../assets/css/bootstrap.min.css" rel="stylesheet">
<link href="../assets/css/materialdesignicons.min.css" rel="stylesheet">
<link href="../assets/css/style.min.css" rel="stylesheet">
</head>
<?php

$my=isset($_GET['my'])?$_GET['my']:null;

if($my=='search' && !empty($_GET['trade_no'])) {
	$trade_no = intval($_GET['trade_no']);
	$sql=" `trade_no`='$trade_no'";
	$numrows=$DB->getColumn("SELECT count(*) from ucenter_order WHERE{$sql}");
	$con='APPID:'.$appid.' 共有 <b>'.$numrows.'</b> 个订单';
	$link="&appid=".$appid;
	if(!empty($_GET['type']) && $_GET['type']!='0'){
		$link.="&type=".$type;
		if(!empty($_GET['openid'])){
			$con='APPID:'.$appid.' openid:'.$openid.' 共有 <b>'.$numrows.'</b> 个订单';
			$link.="&openid=".$openid;
		}
	}
}else{
	$numrows=$DB->getColumn("SELECT count(*) from ucenter_order WHERE 1");
	$sql=" 1";
	$con='系统共有 <b>'.$numrows.'</b> 个订单';
}
$status =$_GET['status'];
if($status!=''){
    $sql .=" and status='$status' ";
}
$static=$DB->getRow("SELECT sum(money) sumMoney,sum(if(status=1,money,0)) successMoney from ucenter_order WHERE $sql ");
$con.=sprintf('<br/>总金额:%f<br/>支付:%f元<br/>失败:%f元',$static['sumMoney'],$static['successMoney'],$static['sumMoney']-$static['successMoney']);
echo '<div class="container-fluid p-t-15">
  
  <div class="row">
    
    <div class="col-lg-12">
      <div class="card">
        <header class="card-header"><div class="card-title">订单列表</div></header>
        <div class="card-body"><form action="order.php" method="GET" class="form-inline"><input type="hidden" name="my" value="search">
  <div class="form-group">
  <select name="status" class="form-control">
  <option value="">全部</option>
  <option value="1">已支付</option>
   <option value="0">未支付</option>
  </select>
    
    <input type="text" class="form-control" name="trade_no" placeholder="订单号" value="'.$_GET['trade_no'].'">
  </div>
  <button type="submit" class="btn btn-primary">搜索</button>&nbsp;<a href="./order.php" class="btn btn-default">重置</a>
</form>';
echo $con;
?>
      <div class="table-responsive">
        <table class="table table-striped">
          <thead><tr><th>ID</th><th>账号</th><th>商品名称</th><th>订单号</th><th>实际金额<br/>支付金额</th><th>支付类型</th><th>创建时间</th><th>状态</th><th>支付时间</th><th>操作</th></tr></thead>
          <tbody>
<?php
$pagesize=30;
$pages=ceil($numrows/$pagesize);
$page=isset($_GET['page'])?intval($_GET['page']):1;
$offset=$pagesize*($page - 1);
$rs=$DB->query("SELECT * FROM ucenter_order WHERE{$sql} order by id desc limit $offset,$pagesize");
function status($status){
    if($status==0){
        return '<span style="color:#999">待支付</span>';
    }else if($status==1){
        return '<span style="color:green">已支付</span>';
    }else if($status==2){
        return '<span style="color:red">已过期</span>';
    }
}
while($res = $rs->fetch())
{
echo '<tr><td><b>'.$res['id'].'</b></td><td>'.$res['pid'].'</td><td>'.$res['name'].'</td><td><b>'.$res['trade_no'].'</b><div>'.$res['out_trade_no'].'</div></td><td>'.$res['money'].'<br/>'.$res['pay_money'].'</td><td>'.$res['type'].'</td><td>'.date('Y-m-d H:i:s',$res['addtime']).'</td><td>'.status($res['status']).'</td><td>'.($res['endtime']?date('Y-m-d H:i:s',$res['endtime']):'').'</td><td></td></tr>';
}
?>
          </tbody>
        </table>
      </div>
<?php
echo'<ul class="pagination">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li><a href="order.php?page='.$first.$link.'">首页</a></li>';
echo '<li><a href="order.php?page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}
$start=$page-10>1?$page-10:1;
$end=$page+10<$pages?$page+10:$pages;
for ($i=$start;$i<$page;$i++)
echo '<li><a href="order.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="disabled"><a>'.$page.'</a></li>';
for ($i=$page+1;$i<=$end;$i++)
echo '<li><a href="order.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '';
if ($page<$pages)
{
echo '<li><a href="order.php?page='.$next.$link.'">&raquo;</a></li>';
echo '<li><a href="order.php?page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}
echo'</ul>';
#分页
?>
    </div>
  </div>
<script>
var items = $("select[default]");
for (i = 0; i < items.length; i++) {
	$(items[i]).val($(items[i]).attr("default")||0);
}
</script>
  <script type="text/javascript" src="../assets/js/jquery.min.js"></script>
<script type="text/javascript" src="../assets/js/popper.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../assets/js/main.min.js"></script>
</body>
</html>